var Photo = function() {
    this.Upload_Url = "http://www.golfinsns.com/UploadFile";

    this.mSource
    this.mQuality = 100;
    this.mDestinationType = navigator.camera.DestinationType.FILE_URI;
    this.mSourceType = null;
    this.mAllowEdit = true;
    this.mEncodingType = Camera.EncodingType.JPEG;
    this.mTargetWidth = 100;
    this.mTargetHeight = 100;
    this.mSaveToPhotoAlbum = false;
    this.mCorrectOrientation = false;

    this.CallBack = null;
};

Photo.prototype = {
    constructor : Photo,
    getPhotoUri : function() {
        return this.photoUri;
    },
    onPhotoDataSuccess : function($imageURI) {
        console.log("Photo onPhotoDataSuccess");
        this.photoUri = $imageURI;
    },
    onPhotoDataFail : function($err) {
        console.log("Photo onPhotoDataFail");
    },
    uploadPhotoByCamera : function($callback) {
        var option = {
            quality : this.mQuality,
            destinationType : this.mDestinationType,
            sourceType : Camera.PictureSourceType.CAMERA,
            allowEdit : this.mAllowEdit,
            encodingType : this.mEncodingType,
            targetWidth : this.mTargetWidth,
            targetHeight : this.mTargetHeight,
            saveToPhotoAlbum : this.mSaveToPhotoAlbum,
            correctOrientation : this.mCorrectOrientation
        };

        if ($callback != undefined) {
            this.CallBack = $callback;
        }

        navigator.camera.getPicture(this.uploadPhoto, this.onPhotoDataFail, option);
    },
    uploadPhoto : function($imageUri) {
        console.log("Photo uploadPhoto");
        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = $imageUri.substr($imageUri.lastIndexOf('/') + 1);
        options.mimeType = "image/jpeg";

        var cc = new CustomConnect();
        var params = new Object();

        cc.getImgFileNameEncode(options.fileName, function($result) {
            options.enc = $result;
            params.enc = $result;
            options.params = params;
            var ft = new FileTransfer();
            ft.upload($imageUri, encodeURI("http://www.golfinsns.com/UploadFile"), function($res) {
                console.log("Photo onUploadSuccess");
                console.log(JSON.stringify($res));
                this.CallBack(true);
            }, function($err) {
                console.log("Photo onUploadFail :: " + $err);
                this.CallBack(false);
            }, options, true);
        });
    },
    onUploadSuccess : function($res) {
        console.log("Photo onUploadSuccess");
    },
    onUploadFail : function($err) {
        console.log("Photo onUploadFail");
    }
};
